package com.example.book.service.impl;

import com.example.book.dao.BookDao;
import com.example.book.dao.BorrowDao;
import com.example.book.dao.impl.BookDaoImpl;
import com.example.book.service.BookService;
import com.example.book.service.BorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class BorrowBookServiceImpl implements BorrowService {
    @Autowired
    private BorrowDao borrowDao;
    @Autowired
    private BookService bookService;
    @Override
    @Transactional
    public Integer borrowBook(String userId, String bookId) {
        bookService.updateBookStatus(bookId,"1");
        return borrowDao.insert(userId,bookId);
    }

    @Override
    @Transactional
    public Integer returnBook(String userId, String bookId) {
        bookService.updateBookStatus(bookId,"0");
        return borrowDao.update(userId,bookId);
    }
}
